<template xmlns:v="http://www.w3.org/1999/html">
  <el-card class="mt15 mb15">
    <!-- 第一行 -->
    <div class="search-filter">
      <el-row :gutter="20">
        <el-col :span="6">
          <sitem label="字典名称：">
            <el-input
              slot="item"
              v-model="listQuery.dictName"
              placeholder="请输入"
              clearable
              @input="handleFilter"
            />
          </sitem>
        </el-col>
        <el-col :span="6">
          <sitem label="字典编码：">
            <el-input
              slot="item"
              v-model="listQuery.dictCode"
              placeholder="请输入"
              clearable
              @input="handleFilter"
            />
          </sitem>
        </el-col>
        <el-col :span="6">
          <sitem label="">
            <el-button
              slot="item"
              v-waves
              class="el-icon-search"
              type="primary"
              style="width: 80px"
              @click="handleFilter"
            >
              搜索
            </el-button>
          </sitem>
        </el-col>
      </el-row>
    </div>
    <!-- 第一行——操作按钮 -->
    <div class="filter-container">
      <el-button type="primary" icon="el-icon-document-add" @click="editShow('新增',null)">添加</el-button>
      <el-button type="primary" icon="el-icon-document-add" @click="refleshCache()">刷新缓存</el-button>
      <el-button type="primary" icon="el-icon-document-add" @click="initEs()">重建索引</el-button>
    </div>

    <!-- / 第一行——操作按钮 -->

    <!-- table表格 -->
    <el-table :data="list" :stripe="true" style="width: 100%">
       <el-table-column align="center" prop="dictName" label="字典名称">  </el-table-column>


        <el-table-column align="center" prop="dictCode" label="字典编码">   </el-table-column>

      <el-table-column align="center" prop="description" label="描述">   </el-table-column>
<!--      <el-table-column align="center" prop="createTime" label="描述">   </el-table-column>-->




      <!-- 操作 -->
      <el-table-column label="操作" align="center" width="350px" >
        <template slot-scope="{ row, $index }"   >
          <el-button type="text"  @click="editShow('修改',row)">编辑</el-button>
          <el-button type="text" @click="editDictItemShow(row.id, $index)">字典配置</el-button>
          <el-button type="text"   @click="delItem(row, $index)">删除</el-button>
        </template>

      </el-table-column>
      <!-- / 操作 -->
    </el-table>
    <!-- / table表格 -->

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      next-text="下一页"
      layout="prev, pager, next, jumper"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @current-change="currentChange"
      @pagination="getList"
    />
    <!-- / 分页 -->
    <!--    <edit-drawer ref="importInformation" @refresh="refresh" />-->
    <!--   -->

    <edit ref="edit" @refresh="refresh" />
    <dictItem ref="dictItem"  />



  </el-card>
</template>

<script>
// import { fetchList } from "@/api/article";
import {block_init} from '@/api/block';
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import edit from './components/edit'

import dictItem from './components/dictItem_list'


import {sys_dict_refleshCache, sys_dict_list,sys_dict_delete} from '@/api/sys_dict'
import editDrawer from "@/views/content-management/components/editDrawer";
import sitem from "@/components/searchItem/index";

export default {
  components: { Pagination, edit,dictItem, sitem},

  data() {
    return {
      total: 0,

      list: [],
      // 新增弹出框
      dialogVisible: false, // 弹出框的显示与隐藏
      listLoading: true,
      //
      //column=createTime&order=desc&field=id,,roleCode,roleName,createTime,action&pageNo=1&pageSize=10
      listQuery: {
        pageNo: 1,
        pageSize: 10,
        field: "id,,,dictName,dictCode,description,action",
        column: "createTime",
        order: "desc"
        // type:"default",
        //  sort: false
      }
    }
  },
  created() {

    this.getList()
  },
  methods: {

    // table表格事件
    indexMethod(index) {
      return index * 2
    },
    editShow(id,rowData) {
      // console.log("the blockId is=======>:"+this.blockId);
      this.$refs.edit.show(id, rowData)
    },
    editDictItemShow(id) {
      console.log("打开窗口 dictItem",id)
      this.$refs.dictItem.show(id)
    },


    initEs() {

      this.$confirm('确定要重建索引吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          block_init({}).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })

          })
          // this.list.splice(index, 1)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },


    refleshCache() {
      this.listLoading = true

      sys_dict_refleshCache({}).then(response => {
       // let list=response.result.records;
        this.$message({
          type: 'success',
          message: '刷新成功!'
        })
      })
    },

    // 列表
    getList() {
      this.listLoading = true

      sys_dict_list(this.listQuery).then(response => {
        let list=response.result.records;
        // for(let i=0;i<list.length;i++){
        //     let e=list[i];
        //     if('enterprise'==e.roleCode||'admin'==e.roleCode){
        //         e.sysFlag=1;//系统内置
        //         e.sysFlag_dictText="系统内置";
        //     }else{
        //        e.sysFlag=0;//
        //        e.sysFlag_dictText="自定义";
        //     }
        // }//end of for
        this.list = list
        // this.total = 1;
        this.total = response.result.total
        this.listLoading = false
      })
    },
    refresh() {
      this.getList()
    },


    // 删除
    delItem(e, index) {

      let p= {
          params: {	// 请求参数拼接在url上
            id: e.id
          }
      };

      this.$confirm('确定要删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          sys_dict_delete(p).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.refresh()
          })
          // this.list.splice(index, 1)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    currentChange(e) {
      console.log(e)
    },
    // 弹出框---分页点击事件
    handleSizeChange() {},
    handleCurrentChange() {},

    // ---------------------------

    // 外部分页 -- 搜索
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList(this.listQuery)

    }
  }
}
</script>
<style lang="scss" scoped></style>
